/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package abricots;

import com.esotericsoftware.minlog.Log;
import java.util.logging.Level;

/**
 *
 * @author charly
 */
public class MyLog {
    
    private String category;
    private final int level;
    private final Log.Logger log;
    private static boolean enabled;
    public final boolean DEBUG;
    public final boolean TRACE;
    
    public MyLog(String category, int level) {
        this.level = level;
        this.category = category;
        log = new Log.Logger();
        DEBUG = this.level <= Log.LEVEL_DEBUG && enabled;
        TRACE = this.level <= Log.LEVEL_TRACE && enabled;
    }
    
    public void log(int level, String cat, String msg, Throwable ex) {
        if (this.level <= level && enabled) {
            log.log(level, category, msg, ex);
        }
    }
    
    public void info(String msg) {
        log(Log.LEVEL_INFO, category, msg, null);
    }
    
    public void info(String msg, Throwable ex) {
        log(Log.LEVEL_INFO, category, msg, ex);
    }
    
    public void debug(String msg) {
        log(Log.LEVEL_DEBUG, category, msg, null);
    }
    
    public void debug(String msg, Throwable ex) {
        log(Log.LEVEL_DEBUG, category, msg, ex);
    }
    
    public void warn(String msg) {
        log(Log.LEVEL_WARN, category, msg, null);
    }
    
    public void warn(String msg, Throwable ex) {
        log(Log.LEVEL_WARN, category, msg, ex);
    }
    
    public void error(String msg) {
        log(Log.LEVEL_ERROR, category, msg, null);
    }
    
    public void error(String msg, Throwable ex) {
        log(Log.LEVEL_ERROR, category, msg, ex);
    }
    
    public void trace(String msg) {
        log(Log.LEVEL_TRACE, category, msg, null);
    }
    
    public void trace(String msg, Throwable ex) {
        log(Log.LEVEL_TRACE, category, msg, ex);
    }
    
    public static void setEnabled(boolean b) {
        enabled = b;
    }
}
